package com.google.code.ptrends.catparsers.utils;

import org.apache.commons.lang.StringUtils;

public class ModelManufacturerPair {
    private String model;
    private String manufacturer;
    private int fHashCode;

    public ModelManufacturerPair(final String model, final String manufacturer) {
	this.model = model;
	this.manufacturer = manufacturer;
    }

    public void setManufacturer(final String manufacturer) {
	this.manufacturer = manufacturer;
    }

    public String getManufacturer() {
	return manufacturer;
    }

    public void setModel(final String model) {
	this.model = model;
    }

    public String getModel() {
	return model;
    }

    @Override
    public int hashCode() {
	if (fHashCode == 0) {
	    fHashCode = 7 + 11 * 13;
	    if (this.getModel() != null && !"".equals(this.getModel()))
		fHashCode ^= this.getModel().hashCode();
	    if (this.getManufacturer() != null && !"".equals(this.getManufacturer()))
		fHashCode /= this.getManufacturer().hashCode();
	}
	return fHashCode;
    }

    @Override
    public boolean equals(Object arg0) {
	if (arg0 == null)
	    return false;
	if (!(arg0 instanceof ModelManufacturerPair))
	    return false;
	final ModelManufacturerPair item = (ModelManufacturerPair) arg0;
	if (!StringUtils.isBlank(this.getModel()) && !StringUtils.isBlank(item.getModel()))
	    if (!this.getModel().equals(item.getModel()))
		return false;
	if (!StringUtils.isBlank(this.getManufacturer())
		&& !StringUtils.isBlank(item.getManufacturer()))
	    if (!this.getManufacturer().equals(item.getManufacturer()))
		return false;
	return true;
    }
}
